package com.seal.commons.generator.vo;

import com.seal.commons.utils.StringUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 功能描述: <br/>
 *
 * @author yong.huang
 * @date: 2020-08-03 20:52<br/>
 * @since JDK 1.8
 */
@Data
public class TableInfo {

    //引入jar包
    private Set<String> importPackages = new HashSet<>();

    /**
     * 表名
     */
    private String name;

    /**
     * 备注
     */
    private String comment;

    /**
     * entity的名字
     */
    private String entityName;

    /**
     * jpa接口名
     */
    private String repositoryName;

    /**
     * BO名
     */
    private String boName;

    /**
     * DTO名称
     */
    private String dtoName;

    /**
     * serviceName
     */
    private String serviceName;

    /**
     * serviceImplName
     */
    private String serviceImplName;

    private String superClassName;

    private TableField pkField;

    /**
     * 字段列表
     */
    private List<TableField> fields = new ArrayList<>();


    public void addImportPackage(String importPackage){
        if(StringUtils.isNotBlank(importPackage)){
            importPackages.add(importPackage);
        }
    }

    public void addFiled(TableField tableField){
        fields.add(tableField);
    }

    public void setPk(String pkName){
        fields.forEach(field->{
            if(field.getName().equals(pkName)){
                pkField = field;
            }
        });
    }

    public TableInfo(String tableName, String comment){
        this.name = tableName;
        this.comment = comment;
    }

}